import { Component, OnInit } from '@angular/core';

import { XiaoRenService } from '../service/xiao-ren.service';

@Component({
  selector: 'app-xiao-ren',
  templateUrl: './xiao-ren.component.html',
  styleUrls: ['./xiao-ren.component.css'],
  providers: [XiaoRenService]
})
export class XiaoRenComponent implements OnInit {

  aid = "";

  buwei = [
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  ];

  buweiRows = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
  buweiLists = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];

  constructor( 
    private xiaoRenService : XiaoRenService

  ) { }

  ngOnInit() {
  }

  clickGrid(row: number, list: number) {
    if (this.buwei[row][list] == 0) {
      this.buwei[row][list] = 1;
    }
    else {
      this.buwei[row][list] = 0;
    }
  }

  save() {
    for (let i = 0; i <= 15; i++) {
      for (let j = 0; j <= 15; j++) {
        if (this.buwei[i][j] == 1) {
          if (i <= 9 && j <= 9) {
            this.aid += `0${i}0${j},`;
          }
          else if (i <= 9 && j >= 10) {
            this.aid += `0${i}${j},`;
          }
          else if (i >= 10 && j <= 9) {
            this.aid += `${i}0${j},`
          }
          else{
            this.aid += `${i}${j},`
          }
        }
      }
    }

    this.xiaoRenService.createXiaoRen(this.aid);

  }
}
